package com.sunfeng.n4.singleton;

public class SingletonTwo {

    private SingletonTwo() {

    }

    private static volatile SingletonTwo INSTANCE = null;

    public static SingletonTwo getInstance() {
        if (INSTANCE != null) {
            return INSTANCE;
        }
        synchronized (SingletonTwo.class) {
            if (INSTANCE != null) {
                return INSTANCE;
            }
            INSTANCE = new SingletonTwo();// volatile 防止重排序
            return INSTANCE;
        }
    }
}
